<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>业务处理-采购订单</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
			<div class="page_header"><a>采购订单</a></div>
			<div class="search">
			<form action="<%=basePath %>purchaseOrder/listPurchaseOrder.do" method="post" class="form">
				<input type="hidden" name="currentPage" value="1">
				<p>
						<label>单号</label>
						<input type="text" class="form-control" name="orderNumber" value="${purchaseOrderPage.orderNumber }"></input>
						<label>采购说明</label>
						<input class="form-control doubleWidth" type="text" name="remarks" value="${purchaseOrderPage.remarks }"></input>
						<label>状态</label>
						<select name="status" class="form-control select">
							<option value="">全部</option>
							<option value="0" <c:if test="${purchaseOrderPage.status==0}">selected</c:if>>未提交</option>
							<option value="1" <c:if test="${purchaseOrderPage.status==1}">selected</c:if>>已提交</option>
							<option value="2" <c:if test="${purchaseOrderPage.status==2}">selected</c:if>>审核中</option>
							<option value="3" <c:if test="${purchaseOrderPage.status==3}">selected</c:if>>已通过</option>
							<option value="4" <c:if test="${purchaseOrderPage.status==4}">selected</c:if>>未通过</option>
						</select>
				</p>
				<p>
						<label>提交人</label>
						<input type="text" class="form-control" name="submitterName" value="${purchaseOrderPage.submitterName }">
						<label class="label1">提交时间</label>
						<input type="text" class="form-control" name="commitTime1" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" value="${purchaseOrderPage.commitTime1 }"></input>
						<label>至</label>
						<input type="text" class="form-control" name="commitTime2" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" value="${purchaseOrderPage.commitTime2 }"></input>
						<label>物料</label>
						<select name="materialMaterial" class="form-control select">
							<option value="">全部</option>
							<option value="IMPA物料" <c:if test="${purchaseOrderPage.materialMaterial=='IMPA物料'}">selected</c:if>>IMPA物料</option>
							<option value="普通物料" <c:if test="${purchaseOrderPage.materialMaterial=='普通物料'}">selected</c:if>>普通物料</option>
						</select>
				</p>
				<p>
						<label>供商代码</label>
						<input type="text" class="form-control" name="supplierCode" value="${purchaseOrderPage.supplierCode }">
						<label>供商名称</label>
						<input type="text" class="form-control" name="supplierName" value="${purchaseOrderPage.supplierName }">
						<label>结算状态</label>
						<select name="isSettle" class="form-control select">
							<option value="">全部</option>
							<option value="0" <c:if test="${purchaseOrderPage.isSettle==0 }">selected</c:if>>未结算</option>
							<option value="1" <c:if test="${purchaseOrderPage.isSettle==1 }">selected</c:if>>已结算</option>
						</select>
					<span class="btn">
						<input type="submit" class="btn btn1" value="查询"></input>
						<input type="button" class="btn btn2" value="清空" onclick="clearSearchParam();"></input>
						<input type="button" class="btn btn1" value="详情" onclick="toEditPurchaseOrder();"></input>
						<input type="button" class="btn btn_danger" value="删除" onclick="toDeletePurchaseOrder();"></input>
					</span>
				</p>
				</form>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th></th>
							<th style="width:180px;">操作</th>
							<th>单号</th>
							<th>采购说明</th>
							<th>品项数</th>
							<th>供应商</th>
							<th>供应代码</th>
							<th>状态</th>
							<th>物料类型</th>
							<th>提交时间</th>
							<th>提交人</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${orderList }" var="order" varStatus="i">
							<tr id="${order.purchaseOrderID }" onclick="selectRow(this);">
								<td><label class="radio"><input type="radio" name="operatePurchaseOrder" value="${order.purchaseOrderID }"><span class="radio_icon"></span></label></td>
								<td>
									<a class="btn btn-xs btn1" onclick="editPurchaseOrder(${order.purchaseOrderID });">详情</a>
								<c:if test="${order.status=='0' }">
									<a class="btn btn-xs btn2" onclick="confirmSubmitPurchaseOrder(${order.purchaseOrderID });">提交</a>
									<a class="btn btn-xs btn_danger" onclick="confirmDeletePurchaseOrder(${order.purchaseOrderID });">删除</a>
								</c:if>
								<c:if test="${order.status==3 && order.isSettle==0 }">
									<a class="btn btn-xs btn2" onclick="confirmSettlePurchaseOrder(${order.purchaseOrderID });">结算</a>
								</c:if>
								</td>
								<td><a onclick="editPurchaseOrder(${order.purchaseOrderID });">${order.orderNumber}</a></td>
								<td>${order.remarks }</td>
								<td>${order.number }</td>
								<td>${order.supplierName }</td>
								<td>${order.supplierCode}</td>
								<td>
									<c:if test="${order.status==0 }">未提交</c:if>
									<c:if test="${order.status==1 }">已提交</c:if>
									<c:if test="${order.status==2 }">审核中</c:if>
									<c:if test="${order.status==3 }">已通过</c:if>
									<c:if test="${order.status==4 }">未通过</c:if>
								</td>
								<td>${order.materialMaterial }</td>
								<td><fmt:formatDate value="${order.commitTime }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
								<td>${order.submitterName }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
		</div>
		<jsp:include page="/jsp/business/purchaseOrder/settle.jsp"></jsp:include>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>My97DatePickers/WdatePicker.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
	
	function clearSearchParam(){
		$(".search input:text").val("");
		$(".search select").val("");
	}
	
	function selectRow(obj){
		$(obj).find('input:radio[name="operatePurchaseOrder"]')[0].checked=true;
	}
	
	function toEditPurchaseOrder(){
		var radio=$('input:radio[name="operatePurchaseOrder"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要编辑的采购订单！");
			return;
		}
		editPurchaseOrder(radio.val());
	}
	
	function editPurchaseOrder(purchaseOrderID){
		location.href="<%=basePath %>purchaseOrder/detail.do?purchaseOrderID="+purchaseOrderID;
	}
	
	function toDeletePurchaseOrder(){
		var radio=$('input:radio[name="operatePurchaseOrder"]:checked');
		if(!radio.val()){
			Prompt.alert("删除提示","请先选中需要删除的采购订单！");
			return;
		}
		confirmDeletePurchaseOrder(radio.val());
	}
		
	function confirmDeletePurchaseOrder(id){
		var delFunc=function(){
			$.ajax({
				url:"<%=basePath %>purchaseOrder/delete.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "purchaseOrderID="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("删除提示","采购订单已删除！",Prompt.refresh);
					}else{
						Prompt.alert("提示","采购订单删除失败！");
					}
				},
				error :function(){
					Prompt.alert("删除提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要删除该采购订单吗?删除后无法恢复",delFunc);
	}
	
	function toSubmitPurchaseOrder(){
		var radio=$('input:radio[name="operatePurchaseOrder"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要提交的采购订单！");
			return;
		}
		confirmSubmitPurchaseOrder(radio.val());
	}
		
	function confirmSubmitPurchaseOrder(id){
		var submitFunc=function(){
			$.ajax({
				url:"<%=basePath %>purchaseOrder/submit.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "purchaseOrderID="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("提示","采购订单已提交！",Prompt.refresh);
					}else{
						Prompt.alert("提示","采购订单提交失败！");
					}
				},
				error :function(){
					Prompt.alert("提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要提交该采购订单吗?",submitFunc);
	}
	</script>
</body>
</html>